package com.erp.myAdapter

import android.annotation.SuppressLint
import androidx.appcompat.app.AlertDialog
import android.content.Context
import android.content.SharedPreferences
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.EditText
import com.erp.R
import com.erp.bean.JieHaoKBean
import com.erp.bean.ProcessInspectionJieHaoBean
import com.erp.mclass.QuanXian
import com.erp.module.jiehao.JieHaoContract
import com.erp.module.zhichengJianyan.ProcessInspectionContract
import com.erp.util.Myutil
import com.erp.util.Sputil
import kotlinx.android.synthetic.main.lv_inspection_item.view.*
import java.text.SimpleDateFormat
import java.util.*

class InspectionAdapter(var jiehaoList: MutableList<ProcessInspectionJieHaoBean>, var context: Context, var jieHaoKP: ProcessInspectionContract.InspectionJieHaoP) : BaseAdapter(){
    var minflater: LayoutInflater = LayoutInflater.from(context)
    var sp: SharedPreferences = Sputil.sp("erp")
    var mtime= Date().time / 1000
    @SuppressLint("ViewHolder", "InflateParams")
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var v : View =minflater.inflate(R.layout.lv_inspection_item,null)
        val jiehao=jiehaoList[position]
        Myutil.settv(jiehao.batch,v.Tv_Jiehao)
        Myutil.settv(Myutil.getdata(jiehao.process_inspection_time),v.Tv_Inspection_time)
        Myutil.settv(Myutil.getdata(jiehao.plan_warehousing_time),v.TvPlanWarehousingTime)
        Myutil.settv(jiehao.process_inspection_name,v.Tv_JianYanRen)
        if(jiehao.getInspection() == "0"){
            v.JieHaoLl.setBackgroundColor(Color.WHITE)
            v.Tv_Jiehao.setTextColor(Color.BLACK)
            v.Tv_Inspection_time.setTextColor(Color.BLACK)
            v.Tv_JianYanRen.setTextColor(Color.BLACK)
            v.Tv_Inspection.visibility = View.GONE
        }else if(jiehao.getInspection() == "1"){
            v.JieHaoLl.setBackgroundColor(Color.LTGRAY)
            v.Tv_Jiehao.setTextColor(Color.GRAY)
            v.Tv_Inspection_time.setTextColor(Color.GRAY)
            v.Tv_JianYanRen.setTextColor(Color.GRAY)
            v.Tv_Inspection.visibility = View.VISIBLE
        }
//        v.Bt_Inspection.setOnClickListener {
//            if(jiehao.getInspection()=="0") {
//                jieHaoKP.InspectionJieHao(jiehaoList[position].batch, "1")
//            }else if(jiehao.getInspection()=="1"){
//                jieHaoKP.InspectionJieHao(jiehaoList[position].batch,  "0")
//            }
//        }
        return v
    }

    override fun getItem(position: Int): Any = jiehaoList[position]

    override fun getItemId(position: Int): Long = position.toLong()

    override fun getCount(): Int = jiehaoList.size
    fun Allnotify(){
        mtime= Date().time / 1000
        notifyDataSetChanged()
    }
}